package com.example.demo;

public class NamingUtils {
    // 将蛇形命名转为驼峰命名（不带前缀下划线）
    public static String snakeToCamel(String snake) {
        if (snake == null || snake.isEmpty()) {
            return snake;
        }

        StringBuilder camelCaseString = new StringBuilder();
        // 用下划线分割
        String[] parts = snake.split(" ");

        for (int i = 0; i < parts.length; i++) {
            // 第一个字母小写，后续的每个单词首字母大写
            if (i == 0) {
                camelCaseString.append(parts[i].toLowerCase());
            } else {
                camelCaseString.append(capitalize(parts[i]));
            }
        }

        return camelCaseString.toString();
    }

    // 首字母大写的方法
    private static String capitalize(String word) {
        if (word == null || word.isEmpty()) {
            return word;
        }
        return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
    }

    // 测试
//    public static void main(String[] args) {
//        String snakeCase = "order table name";
//        String camelCase = snakeToCamel(snakeCase);
//        System.out.println("Snake Case: " + snakeCase);
//        System.out.println("Camel Case: " + camelCase);
//    }
}
